package util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;

public class FiltroDeRequest implements ContainerRequestFilter {

	private Criptografia cript;
	
	@Override
	public ContainerRequest filter(ContainerRequest request) {
		cript = Criptografia.getInstance();
		System.out.println("Entrou no request");
		System.out.println(request.getMethod());
		
		// if (request.getEntityInputStream() != null) {
		// InputStream in = request.getEntityInputStream();
		// String result = null;
		// try {
		// result = toString(in);
		// } catch (IOException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		// System.out.println(result);
		//
		// }
		
		return request;
	}
	private String toString(InputStream is) throws IOException {
		byte[] bytes = new byte[1024];
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		int lidos;
		while ((lidos = is.read(bytes)) > 0) {
			baos.write(bytes, 0, lidos);
		}
		String result = new String(baos.toByteArray());
	//	is.close();
		return result;
	}
}